-
Notifications
You must be signed in to change notification settings - Fork 0
/
InitBean.java
59 lines (48 loc) · 2 KB
/
InitBean.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package at.htl.MovieManager.business;
import at.htl.MovieManager.model.Movie;
import at.htl.MovieManager.model.Person;
import io.quarkus.runtime.StartupEvent;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonValue;
import javax.transaction.Transactional;
import java.util.List;
@ApplicationScoped
public class InitBean {
@Inject
@RestClient
MovieManagerService movieManagerService;
@Inject
MovieDAO movieDAO;
@Inject
PersonDAO personDAO;
@Transactional
void init(@Observes StartupEvent ev)
{
System.err.println("Init started!");
JsonArray peopleJsonArray = movieManagerService.getPeople(20, 0);
for (JsonValue personJson: peopleJsonArray) {
JsonObject personJsonObject = personJson.asJsonObject();
String name = personJsonObject.getString("name");
String gender = personJsonObject.getString("gender");
String age = personJsonObject.getString("age");
Person person = new Person(name, gender, age);
personDAO.persist(person);
}
JsonArray filmsJsonArray = movieManagerService.getFilms(20,0);
for (JsonValue filmJson: filmsJsonArray) {
JsonObject movieJsonObject = filmJson.asJsonObject();
String title = movieJsonObject.getString("title");
String dir = movieJsonObject.getString("director");
int date = movieJsonObject.isNull("release_date") ? 0:Integer.parseInt(movieJsonObject.getString("release_date"));
int score = movieJsonObject.isNull("rt_score") ? 0:Integer.parseInt(movieJsonObject.getString("rt_score"));
List<Person> persons = personDAO.getAll(0, 100);
Movie movie = new Movie(title, dir, date, score, persons);
movieDAO.persist(movie);
}
}
}